package com.wingscode.modules.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wingscode.common.annotation.SysLog;
import com.wingscode.common.utils.R;
import com.wingscode.common.validator.ValidatorUtils;
import com.wingscode.common.validator.group.AddGroup;
import com.wingscode.common.validator.group.UpdateGroup;
import com.wingscode.modules.common.entity.WebsiteEntity;
import com.wingscode.modules.common.service.WebSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 平台配置
 *
 * @author yan
 */
@RestController
@RequestMapping("/website")
public class WebsiteController extends AbstractController {
	@Autowired
	private WebSiteService webSiteService;

	/**
	 * 详情
	 */
	@RequestMapping("/info")
	public R info(){
		List<WebsiteEntity> list = webSiteService.list();
		if (list != null && list.size() > 0)
			return R.ok().put("website", list.get(0));

        return R.ok();
	}
	
	/**
	 * 保存
	 */
	@PostMapping("/save")
	public R save(@RequestBody WebsiteEntity entity){
		ValidatorUtils.validateEntity(entity, AddGroup.class);

		webSiteService.save(entity);

		return R.ok();
	}

	/**
	 * 修改平台配置
	 */
	@PostMapping("/update")
	public R update(@RequestBody WebsiteEntity entity){
		ValidatorUtils.validateEntity(entity, UpdateGroup.class);

		webSiteService.updateById(entity);

		return R.ok();
	}
}
